package org.tinygame.herostory;

import io.netty.channel.Channel;
import io.netty.channel.group.ChannelGroup;
import io.netty.channel.group.DefaultChannelGroup;
import io.netty.util.concurrent.GlobalEventExecutor;

/**
 * @author anan
 * @create 2022-05-01 23:32
 */
public final class Broadcaster {
    static final private ChannelGroup _channelGroup = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);

    private Broadcaster() { }

    /**
     * 添加信道
     */
    static public void addChannel(Channel ch){
        if(null != ch){
            _channelGroup.add(ch);
        }
    }

    static public void removeChannel(Channel ch){
        if(null != ch){
            _channelGroup.remove(ch);
        }
    }

    static public void broadcast(Object msg){
        if(null != msg){
            _channelGroup.writeAndFlush(msg);
        }
    }
}
